package com.colorfruit.admin.control.controller;

import com.colorfruit.admin.business.service.DictService;
import com.colorfruit.admin.pojo.entity.FoundationDictionary;
import com.colorfruit.admin.pojo.enums.ErrorCodeEnum;
import com.colorfruit.framework.model.pojo.BaseResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/dict")
public class DictionaryController {

    @Autowired
    DictService dictService;

    /**
     * 根据字典类型查询字典值
     *  variety  place    standard type     brand    label    package
     *  商品品种 商品产地 商品规格 商品类别 商品品牌 商品标签 包装类别
     * @param dictType
     * @return
     */
    @RequestMapping("/selectDictListByCode")
    public BaseResult selectDictListByCode(String dictType, String name){
        try {
            log.info("# [IN] [controller] getDictListByCode param: dictType = {}",dictType);
            List<FoundationDictionary> foundationDictionaries = dictService.selectDictListByType(dictType, name);
            log.info("# [OUT] [controller] getDictListByCode SUCCESS");
            return new BaseResult(foundationDictionaries);
        }catch (Exception e){
            log.error("# [OUT] errorMessage: " + e.getMessage(), e);
            return new BaseResult(ErrorCodeEnum.SYSTEM_ERROR.getCode(), ErrorCodeEnum.SYSTEM_ERROR.getMsg());
        }
    }


}
